package com.ruoyi.group.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.group.domain.RepairOrderTransfer;
import com.ruoyi.group.domain.dto.RepairOrderTransferDto;
import com.ruoyi.group.domain.dto.RpTransferDto;
import com.ruoyi.group.service.RepairOrderTransferService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: 鲜涛  <br/>
 * Date: 2022/3/12:9:46  <br/>
 * Description:处理工单转接，是否转接来更改状态
 */
@Api(value = "/transfer" ,description = "查找需要转接的工单内容")
@RestController
@RequestMapping("/transfer")
public class RepairOrderTransferController extends BaseController {
    @Autowired
    private RepairOrderTransferService repairOrderTransferService;

    @ApiOperation(value = "/list", httpMethod = "POST", response = AjaxResult.class)
    @PostMapping("/list")
    public AjaxResult list(RepairOrderTransfer repairOrderTransfer)
    {
        List<RepairOrderTransfer> transfers = repairOrderTransferService.selectTransferList(repairOrderTransfer);
        return AjaxResult.success(transfers);
    }

    /*/*
     * Description :通过工单编号查询转接详情信息  <br/>
     * ChangeLog : 1. 创建 (2022/3/14 10:49 [admin]);
     ** @param null
     * *  @return null
    */

    @ApiOperation(value = "/find", httpMethod = "POST", response = AjaxResult.class)
    @PostMapping("/find/{orderNo}")
    public AjaxResult getInfo(@PathVariable("orderNo") String orderNo){
        RepairOrderTransferDto transferList=repairOrderTransferService.findByOrderNo(orderNo);

        return AjaxResult.success(transferList);
    }
    /*/*
     * Description : 同意转接申请，
     * ChangeLog : 1. 创建 (2022/3/16 17:01 [admin]);
     ** @param null
     * *  @return null
    */
    @ApiOperation(value="/receive",httpMethod = "POST",response = AjaxResult.class)
    @PostMapping("/receive")
    public AjaxResult subTransfer(@RequestBody RpTransferDto rpTransferDto){

        String orderNo=rpTransferDto.getOrderNo();
        String deptName = rpTransferDto.getDeptName();
        String nickName = rpTransferDto.getNickName();

        int i = repairOrderTransferService.updateTansfer(orderNo,deptName,nickName);
        if(i>0){
            return  AjaxResult.success();
        }else {
            return AjaxResult.error();
        }
    }

    /*/*
     * Description : 拒绝转接申请
     * ChangeLog : 1. 创建 (2022/3/16 17:02 [admin]);
     ** @param null
     * *  @return null
    */
    @ApiOperation(value="/refuse",httpMethod = "POST",response = AjaxResult.class)
    @PostMapping("/refuse")
    public AjaxResult subRefuse(@RequestBody RpTransferDto rpTransferDto){
        String orderNo=rpTransferDto.getOrderNo();
        String deptName = rpTransferDto.getDeptName();
        String nickName = rpTransferDto.getNickName();
        int i = repairOrderTransferService.updateRefuse(orderNo,deptName,nickName);
        if(i>0){
            return  AjaxResult.success();
        }else {
            return AjaxResult.error();
        }
    }
}
